package com.esri.core.tasks.na;

import com.esri.core.geometry.Envelope;
import com.esri.core.geometry.GeometryEngine;
import com.esri.core.internal.util.d;
import com.esri.core.map.FeatureSet;
import com.esri.core.map.Graphic;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;

/* loaded from: classes.dex */
public class ClosestFacilityResult extends NAResult {
    private List<Route> routes = new ArrayList();
    private FeatureSet facilities = null;
    private FeatureSet incidents = null;

    public List<Route> getRoutes() {
        return new ArrayList(this.routes);
    }

    public FeatureSet getFacilities() {
        if (this.facilities == null) {
            return null;
        }
        FeatureSet featureSet = new FeatureSet();
        featureSet.setGraphics(this.facilities.getGraphics());
        featureSet.setSpatialReference(this.facilities.getSpatialReference());
        return featureSet;
    }

    public FeatureSet getIncidents() {
        if (this.incidents == null) {
            return null;
        }
        FeatureSet featureSet = new FeatureSet();
        featureSet.setGraphics(this.incidents.getGraphics());
        featureSet.setSpatialReference(this.incidents.getSpatialReference());
        return featureSet;
    }

    public static ClosestFacilityResult fromJson(JsonParser jsonParser) throws Exception {
        if (d.c(jsonParser)) {
            ClosestFacilityResult closestFacilityResult = new ClosestFacilityResult();
            HashMap hashMap = new HashMap();
            ArrayList arrayList = new ArrayList();
            while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
                String currentName = jsonParser.getCurrentName();
                jsonParser.nextToken();
                if ("directions".equals(currentName)) {
                    if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                        while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                            Route route = new Route();
                            while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
                                String currentName2 = jsonParser.getCurrentName();
                                jsonParser.nextToken();
                                if ("routeId".equals(currentName2)) {
                                    route.routeID = jsonParser.getIntValue();
                                } else if ("routeName".equals(currentName2)) {
                                    route.routeName = jsonParser.getText();
                                } else if ("summary".equals(currentName2)) {
                                    if (jsonParser.getCurrentToken() == JsonToken.START_OBJECT) {
                                        while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
                                            String currentName3 = jsonParser.getCurrentName();
                                            jsonParser.nextToken();
                                            if ("totalLength".equals(currentName3)) {
                                                route.totalLength = jsonParser.getDoubleValue();
                                            } else if ("totalTime".equals(currentName3)) {
                                                route.totalTime = jsonParser.getDoubleValue();
                                            } else if ("totalDriveTime".equals(currentName3)) {
                                                route.totalDriveTime = jsonParser.getDoubleValue();
                                            } else if ("envelope".equals(currentName3) && jsonParser.getCurrentToken() == JsonToken.START_OBJECT) {
                                                route.envelope = (Envelope) GeometryEngine.jsonToGeometry(jsonParser).getGeometry();
                                            }
                                        }
                                    }
                                } else if ("features".equals(currentName2) && jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                                    while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                                        route.routingDirections.add(RouteDirection.fromJson(jsonParser));
                                    }
                                }
                            }
                            hashMap.put(Integer.valueOf(route.routeID), route);
                        }
                    }
                } else {
                    if ("routes".equals(currentName)) {
                        for (Graphic graphic : FeatureSet.fromJson(jsonParser, false, -1).getGraphics()) {
                            arrayList.add(graphic);
                        }
                    } else if ("facilities".equals(currentName)) {
                        closestFacilityResult.facilities = FeatureSet.fromJson(jsonParser, false, -1);
                    } else if ("incidents".equals(currentName)) {
                        closestFacilityResult.incidents = FeatureSet.fromJson(jsonParser, false, -1);
                    } else if ("barriers".equals(currentName)) {
                        closestFacilityResult.pointBarriers = FeatureSet.fromJson(jsonParser, false, -1);
                    } else if ("polylineBarriers".equals(currentName)) {
                        closestFacilityResult.polylineBarriers = FeatureSet.fromJson(jsonParser, false, -1);
                    } else if ("polygonBarriers".equals(currentName)) {
                        closestFacilityResult.polygonBarriers = FeatureSet.fromJson(jsonParser, false, -1);
                    } else if ("messages".equals(currentName)) {
                        if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                            closestFacilityResult.messages = new ArrayList();
                            while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                                closestFacilityResult.messages.add(NAMessage.fromJson(jsonParser));
                            }
                        }
                    } else {
                        jsonParser.skipChildren();
                    }
                }
            }
            if (!hashMap.isEmpty()) {
                Iterator it = arrayList.iterator();
                while (it.hasNext()) {
                    Graphic graphic2 = (Graphic) it.next();
                    ((Route) hashMap.get(Integer.valueOf(((Integer) graphic2.getAttributeValue("ObjectID")).intValue()))).route = graphic2;
                }
                closestFacilityResult.routes.addAll(hashMap.values());
            } else {
                Iterator it2 = arrayList.iterator();
                while (it2.hasNext()) {
                    Route route2 = new Route();
                    route2.route = (Graphic) it2.next();
                    closestFacilityResult.routes.add(route2);
                }
            }
            return closestFacilityResult;
        }
        return null;
    }

    @Override // com.esri.core.tasks.na.NAResult
    public int hashCode() {
        int hashCode = super.hashCode() * 31;
        FeatureSet featureSet = this.facilities;
        int hashCode2 = (hashCode + (featureSet == null ? 0 : featureSet.hashCode())) * 31;
        FeatureSet featureSet2 = this.incidents;
        int hashCode3 = (hashCode2 + (featureSet2 == null ? 0 : featureSet2.hashCode())) * 31;
        List<Route> list = this.routes;
        return hashCode3 + (list != null ? list.hashCode() : 0);
    }

    @Override // com.esri.core.tasks.na.NAResult
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (super.equals(obj) && getClass() == obj.getClass()) {
            ClosestFacilityResult closestFacilityResult = (ClosestFacilityResult) obj;
            FeatureSet featureSet = this.facilities;
            if (featureSet == null) {
                if (closestFacilityResult.facilities != null) {
                    return false;
                }
            } else if (!featureSet.equals(closestFacilityResult.facilities)) {
                return false;
            }
            FeatureSet featureSet2 = this.incidents;
            if (featureSet2 == null) {
                if (closestFacilityResult.incidents != null) {
                    return false;
                }
            } else if (!featureSet2.equals(closestFacilityResult.incidents)) {
                return false;
            }
            List<Route> list = this.routes;
            if (list == null) {
                if (closestFacilityResult.routes != null) {
                    return false;
                }
            } else if (!list.equals(closestFacilityResult.routes)) {
                return false;
            }
            return true;
        }
        return false;
    }

    public String toString() {
        return "ClosestFacilityResult [Facilities=" + this.facilities + "]";
    }
}
